<?php
include('general_include.php');
include("class/json.php");
$action = $_REQUEST['action'];
if($action == 'sendLostPwd')
{
  $email = trim($_POST['email_id']);
  if(!empty($email))
  {
     $SqlPwd = "SELECT * FROM ".TABLEPREFIX."_user WHERE email = ".mysql_quote($email)." AND is_active='Y'";
	 $RsPwd = $adodbcon->Execute($SqlPwd);	
	 $NumRow = $RsPwd->NumRows();
	 
	 $ContactSql = "SELECT admin_email FROM ".TABLEPREFIX."_admin WHERE  admin_id=1";
     $Contact_email = $UserManagerObjAjax->GetRecords("Row",$ContactSql);
     $admin_email=$Contact_email['admin_email'];
	 if($NumRow>0)
	 {
	    $RowPwd = $RsPwd->FetchRow();
		if(stripslashes($RowPwd['email']) == $email)
		{
		   $password = $RowPwd['password'];
		   $name = $RowPwd['name'];
		   // sending mail //
			$fromarray = array('name' => SITE_NAME, 'email' => SITE_NAME);
			$toarray = array('name' => $name, 'email' => $email);
			$subject = "Login information from " . SITE_NAME;
		
			$TemplateFile="email_templates/forgot_password.html";
			$TemplateFileHandler=fopen($TemplateFile,"r");
			$TemplateMessage=fread($TemplateFileHandler,filesize($TemplateFile));
			
			fclose($TemplateFileHandler);
			
			$TemplateMessage=str_replace("[SITEURL]",$site_url,$TemplateMessage);
			$TemplateMessage=str_replace("[NAME]",$name,$TemplateMessage);
			$TemplateMessage=str_replace("[EMAIL]",$email,$TemplateMessage);
			$TemplateMessage=str_replace("[PASSWORD]",$password,$TemplateMessage);
			
			//send_common_mail($fromarray,$toarray,$subject,$TemplateMessage);
			
			$headers  = 'MIME-Version: 1.0' . "\r\n";
			$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
			$headers .= 'From:'.$admin_email . "\r\n" .
						'X-Mailer: PHP/' . phpversion();
						
			mail($email, $subject, $TemplateMessage, $headers);			
			
			echo '1';
		   
		}
		else
		{
			#Record not found in database, Authentication failed
			echo '2';
		}
	 }
	 else
		{
				echo '3';
		}
  
  }
}
